/*     */ package cn.zzuisa.news.repository.dao;

/*     */
/*     */ import cn.zzuisa.news.repository.NewsTypeRepository;
/*     */ import cn.zzuisa.news.util.JDBCUtil;
/*     */ import java.sql.Connection;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;

/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */
/*     */ public class NewsTypeDAO/*     */ implements NewsTypeRepository
/*     */ {
	Connection conn = null;
	Statement statement = null;
	ResultSet resultSet = null;
	PreparedStatement prepareStatement = null;

	/*     */ public List<String> types(Integer id) {
		/* 30 */ conn = JDBCUtil.getConnection();
		/* 31 */ statement = null;
		/* 32 */ resultSet = null;
		/* 33 */ String sql = "select name from news_type where type in (select type_id from news_info_type where news_id = "
				+
				/* 34 */ id + ")";
		/*     */ try {
			/* 36 */ statement = conn.createStatement();
			/* 37 */ resultSet = statement.executeQuery(sql);
			/* 38 */ List<String> types = new ArrayList<String>();
			/* 39 */ while (resultSet.next()) {
				/* 40 */ types.add(resultSet.getString("name"));
				/*     */ }
			/* 42 */ System.out.println(types.toString());
			/* 43 */ return types;
			/*     */ }
		/* 45 */ catch (SQLException e) {
			/*     */
			/* 47 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 50 */ JDBCUtil.close(conn, statement, resultSet);
				/* 51 */ } catch (Exception e) {
				/*     */
				/* 53 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 56 */ return null;
		/*     */ }

	/*     */
	/*     */
	/*     */ public List<String> showTypes() {
		/* 61 */ conn = JDBCUtil.getConnection();
		/* 62 */ statement = null;
		/* 63 */ resultSet = null;
		/* 64 */ String sql = "select name from news_type";
		/*     */ try {
			/* 66 */ statement = conn.createStatement();
			/* 67 */ resultSet = statement.executeQuery(sql);
			/* 68 */ List<String> types = new ArrayList<String>();
			/* 69 */ while (resultSet.next()) {
				/* 70 */ types.add(resultSet.getString("name"));
				/*     */ }
			/* 72 */ return types;
			/*     */ }
		/* 74 */ catch (SQLException e) {
			/*     */
			/* 76 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 79 */ JDBCUtil.close(conn, statement, resultSet);
				/* 80 */ } catch (Exception e) {
				/*     */
				/* 82 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 85 */ return null;
		/*     */ }

	/*     */
	/*     */
	/*     */ public List<String> showTypesId() {
		/* 90 */ conn = JDBCUtil.getConnection();
		/* 91 */ statement = null;
		/* 92 */ resultSet = null;
		/* 93 */ String sql = "select type from news_type";
		/*     */ try {
			/* 95 */ statement = conn.createStatement();
			/* 96 */ resultSet = statement.executeQuery(sql);
			/* 97 */ List<String> types = new ArrayList<String>();
			/* 98 */ while (resultSet.next()) {
				/* 99 */ types.add(resultSet.getString("type"));
				/*     */ }
			/* 101 */ return types;
			/*     */ }
		/* 103 */ catch (SQLException e) {
			/*     */
			/* 105 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 108 */ JDBCUtil.close(conn, statement, resultSet);
				/* 109 */ } catch (Exception e) {
				/*     */
				/* 111 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 114 */ return null;
		/*     */ }

	/*     */
	/*     */
	/*     */ public boolean add(String name) {
		/* 119 */ conn = JDBCUtil.getConnection();
		/* 120 */ prepareStatement = null;
		/* 121 */ resultSet = null;
		/* 122 */ int max = 0, flag = 0;
		/* 123 */ String maxidSql = "select max(id) id from news_type";
		/* 124 */ String sql = "insert into `news_type` (type,name) values (?,?)";
		/*     */ try {
			/* 126 */ prepareStatement = conn.prepareStatement(maxidSql);
			/* 127 */ resultSet = prepareStatement.executeQuery();
			/* 128 */ if (resultSet.next())
				/* 129 */ max = resultSet.getInt("id") + 1;
			/* 130 */ prepareStatement = conn.prepareStatement(sql);
			/* 131 */ prepareStatement.setInt(1, max);
			/* 132 */ prepareStatement.setString(2, name);
			/* 133 */ flag = prepareStatement.executeUpdate();
			/*     */ }
		/* 135 */ catch (SQLException e) {
			/*     */
			/* 137 */ e.printStackTrace();
			/*     */ } finally {
			/*     */ try {
				/* 140 */ JDBCUtil.close(conn, prepareStatement, resultSet);
				/* 141 */ } catch (Exception e) {
				/*     */
				/* 143 */ e.printStackTrace();
				/*     */ }
			/*     */ }
		/* 146 */ return (flag > 0);
		/*     */ }
	/*     */ }

/*
 * Location:
 * /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/repository/dao/
 * NewsTypeDAO.class Java compiler version: 8 (52.0) JD-Core Version: 1.0.7
 */